<template>
  <div>
    <router-view />
  </div>
</template>

<script setup>
import { ref, onBeforeMount } from 'vue';
import { getCurrentUserPower } from '@/api/common';
const stateUser = ref({
  dormitoryIds: [],
  scoringDormitoryIds: [],
  isHostel: false,
  dormitoryList: [],
  sectionList: []
});

getCurrentUserPower().then(res => {
  console.log('home页面-----------pp', res);
  if (res.data.code === 200) {
    stateUser.value.isHostel = res.data.data.isHostel;
    stateUser.value.scoringDormitoryIds = res.data.data.scoringDormitoryIds;
    // console.log(res.data.data.dormitoryList, '332322');
    let data = [];
    let obj = {};
    /* eslint-disable */
    // 宿舍
    res.data.data.dormitoryList.forEach(item => {
      obj = {
        name: item.dormitoryName,
        id: item.dormitoryId,
        dormitoryName: item.dormitoryName,
        dormitoryId: item.dormitoryId,
        isLeaf: false,
        children: []
      };
      let objSrorey = {};
      if (item.floorList) {
        item.floorList.forEach(itemFloor => {
          objSrorey = {
            name: itemFloor.floorName,
            id: itemFloor.floorId,
            floorName: itemFloor.floorName,
            floorId: itemFloor.floorId,
            isLeaf: false,
            children: []
          };
          if (itemFloor.roomList) {
            itemFloor.roomList.forEach(itemRoom => {
              objSrorey.children.push({
                ...itemRoom,
                isLeaf: true
              });
            });
          }
          obj.children.push(objSrorey);
        });
      }
      data.push(obj);
      /* eslint-enable */
    });
    // console.log(data, '宿舍');
    stateUser.value.dormitoryList = data;
    // 学段
    /* eslint-disable */
    let sectionList = [];
    res.data.data.sectionList.forEach(item => {
      obj = {
        name: item.sectionName,
        id: item.sectionCode,
        sectionCode: item.sectionCode,
        sectionName: item.sectionName,
        isLeaf: false,
        label: item.sectionName,
        value: item.sectionCode,
        children: [],
        classIds: []
      };
      let objSrorey = {};
      if (item.gradeList) {
        item.gradeList.forEach(itemFloor => {
          objSrorey = {
            name: itemFloor.gradeName,
            id: itemFloor.gradeId,
            gradeName: itemFloor.gradeName,
            gradeId: itemFloor.gradeId,
            label: itemFloor.gradeName,
            value: itemFloor.gradeId,
            isLeaf: false,
            children: [],
            classIds: []
          };
          if (itemFloor.classIds) {
            itemFloor.classIds.forEach(itemRoom => {
              obj.classIds.push(itemRoom.classId);
              objSrorey.classIds.push(itemRoom.classId);
              objSrorey.children.push({
                name: itemRoom.className,
                id: itemRoom.classId,
                label: itemRoom.className,
                value: itemRoom.classId,
                className: itemRoom.className,
                classId: itemRoom.classId,
                isLeaf: true
              });
            });
          }
          obj.children.push(objSrorey);
        });
      }
      sectionList.push(obj);
    });
    // console.log(sectionList, 'sectionList');
    stateUser.value.sectionList = sectionList;
    /* eslint-enable */
    if (res.data.data.dormitoryIds) stateUser.value.dormitoryIds = res.data.data.dormitoryIds;
    localStorage.setItem('STATE_USER', JSON.stringify(stateUser.value));
  }
});
</script>

<style lang="less" scoped></style>
